<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;

class Customer extends Model
{
    protected $table = 'customer';
    protected $guarded = ['id'];

    protected $appends = ['type_name','source_name'];

    public function getTypeNameAttribute()
    {
        return $this->attributes['type_name'] = Arr::get(config('freeswitch.customer_type'),$this->type,'无');
    }

    public function getSourceNameAttribute()
    {
        return $this->attributes['source_name'] = Arr::get(config('freeswitch.customer_source'),$this->source,'无');
    }

    public function fields()
    {
        return $this->belongsToMany('App\Models\CustomerField','customer_field_value','customer_id','customer_field_id')
            ->where('visiable',1)
            ->orderBy('sort','asc')
            ->withPivot(['id','data']);
    }

}
